'use strict';

const os = require('os');

function getIpAddress() {
    let ifaces = os.networkInterfaces();
    if (ifaces.hasOwnProperty('eth0')) {
        let eth0 = ifaces.eth0[0];
        if (eth0.hasOwnProperty('address')) {
            return eth0.address;
        }
    }
    return "0.0.0.0";
}

function getLocalName(prefix) {
    let ip = getIpAddress();
    let parts = ip.split('.');
    let hostname = os.hostname();
    return `${prefix}-${parts[2]}-${parts[3]}-${hostname}`
}

module.exports = {
   getLocalName: getLocalName
};